﻿package src.computation.distributionLaw 
{
	
	/**
	* 
	* Reliability project
	* -----------------------
	* @author  Dmitrij Boycov
	* @mail    dmitry.boycov@gmail.com
	* @date    April 27, 2010
	* @version 1
	* 
	*/
	
	// src
	import src.computation.distributionLaw.AbstractLaw
	import src.util.Utils;
	// flash
	import fl.controls.TextInput;
	// astra
	import com.yahoo.astra.containers.formClasses.FormItem;	

	
	public class ConstLaw extends AbstractLaw {
		
		private var probability;
		private var probabilityTf;		
		public static var TYPE = "const";
		
		public function ConstLaw() {
			this.probabilityTf = Utils.numberInputText();
			if (this.probability != null) {
				this.probabilityTf.text = this.probability;
			}
			var probabilityItem = new FormItem("Вероятность", this.probabilityTf);
			probabilityItem.labelWidth = 90;
			this.addChild(probabilityItem);
			this.desc = "Const. Probability do not depend on time."
		}		
		
		public override function getProbabilty(time = null) {
			this.probability = Number(this.probabilityTf.text);
			return Number(this.probabilityTf.text);
		}
		
		public override function random():Number {
			if(this.probability == null){
				this.probability = Number(this.probabilityTf.text);
			}			
			return this.probability*this.time;
		}
		
		public override function toXML():String {
			var str = "<law>";
			str += "<type>" + ConstLaw.TYPE + "</type>";
			str += "<params><probability>" + Number(this.probabilityTf.text) + "</probability></params>";
			str += "</law>";
			return str;
		}
		
	}
	
}